<?php
require_once("../resources/commons.php");
require_once("finance_commons.php");
require_once("../data/User.php");
require_once("../data/Expense.php");

/**
 * Delete the specified expense
 * @param Activity $p_record
 */
function deleteExpense($p_record){
	?>
	<a href="delete_expenditure.php?id=<?=base64_encode($p_record->getId()) ?>">Delete</a>
	<?php
}

SessionManager::getInstance()->checkSession();
checkFinanceAdminRights();
displayTop("Expenditure management",null,null);
$l_userId=SessionManager::getInstance()->getCurrentLoggedUserId();
$l_expenses=Expense::getAll();

if(count($l_expenses)!=0){
	$tableData=new TableData("ExpenseManagementTable");
	$tableData->setRecords($l_expenses);
	$tableData->addHeader("created","Date");
	$tableData->addHeader("holder","Account");
	$tableData->addHeader("description","Description");
	$tableData->addHeader("expenseTypeLabel","Type");
	$tableData->addHeader("amount","Amount");
	$tableData->addAction("deleteExpense");
	
	displayTable($tableData);
}else{
	?>
	<div style="color: white;background-color: red;">No expenses</div>
	<?php
}

displayBottom();
?>